package com.leung.mybatis.binding;


import com.leung.mybatis.session.SqlSession;

import java.lang.reflect.Proxy;
import java.util.Map;

/**
 * @author 丨一
 * @version 1.0
 * @title MapperProxyFactory
 * @description: 映射器代理工厂
 * @date 2025/10/8 上午10:06
 */
public class MapperProxyFactory<T> {

    private final Class<T> mapperInterface;

    public MapperProxyFactory(Class<T> mapperInterface) {
        this.mapperInterface = mapperInterface;
    }


    public T newInstance(SqlSession sqlSession) {

        MapperProxy<T> mapperProxy = new MapperProxy<>(mapperInterface, sqlSession);

        return  (T) Proxy.newProxyInstance(mapperProxy.getClass().getClassLoader(), new Class[]{mapperInterface}, mapperProxy);
    }
}
